#include <iostream>
#include <string>
#include <vector>
#include "MprpcApplication.h"
#include "RpcProvider.h"
#include "Logger.h"
#include "friend.pb.h"

class FriendService : public fixbug::FriendServiceRpc
{
public:
    std::vector<std::string> GetFriendList(uint32_t userid)
    {
        // 设置日志级别
        Logger::getInstance().SetLogLevel(Logger::FATAL);

        // 设置日志文件最大大小
        Logger::getInstance().SetMaxFileSize(10240);

        // 设置日志文件路径
        Logger::getInstance().SetLogPath("./FriendServiceLog/");

        LOGD("now now now %d", 112);

        std::vector<std::string> vec;
        vec.push_back("jmm");
        vec.push_back("azq");
        vec.push_back("hhh");
        return vec;
    }

    virtual void GetFriendList(::google::protobuf::RpcController *controller,
                               const ::fixbug::GetFriendListRequest *request,
                               ::fixbug::GetFriendListResponse *response,
                               ::google::protobuf::Closure *done)
    {
        uint32_t userid = request->userid();
        std::vector<std::string> friendList = GetFriendList(userid);
        response->mutable_result()->set_errcode(0);
        response->mutable_result()->set_errmsg("");
        for (auto name : friendList)
        {
            std::string *p = response->add_friends();
            *p = name;
        }
        done->Run();
    }
};

int main(int argc, char **argv)
{
    MprpcApplication::Init(argc, argv);

    RpcProvider provider;
    provider.NotifyService(new FriendService());

    provider.Run();

    return 0;
}
